# -*- encoding=utf8 -*-
__author__ = "wangnan"

from airtest.core.api import *
from airtest.cli.parser import cli_setup

if not cli_setup():
    auto_setup(__file__, logdir=True, devices=["Android:///",])

# script content
print("start...")

from poco.drivers.android.uiautomation import AndroidUiautomationPoco
poco = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False)

#启动
poco("库课网校").click()
wait(Template(r"tpl1736993968628.png", record_pos=(0.009, 0.799), resolution=(1080, 1920)))

if exists(Template(r"tpl1736992607515.png", record_pos=(0.003, -0.075), resolution=(1080, 1920))):
    poco("android.widget.FrameLayout").child("android.view.View").child("android.view.View").child("android.widget.ImageView").click()
else:
    print('不存在广告')
poco("com.kuke:id/tv_login").click()

#登录
poco("com.kuke:id/tv_title_right").click()
poco("com.kuke:id/et_password_login_phone").set_text('19233829732')
poco("com.kuke:id/et_password").set_text('wn123456789')
poco("com.kuke:id/cb_privacy").click()
poco("com.kuke:id/tv_password_login").click()
poco(text="我的").click()
name = poco("com.kuke:id/tv_nick_name").get_text()
assert_equal(name, "测试",msg="登录后用户名断言是否是测试")


#我的页面-退出登录
swipe(Template(r"tpl1736993243803.png", record_pos=(-0.006, 0.01), resolution=(1080, 1920)), vector=[0, -1])
poco(text="账号设置").click()
poco("退出登录").click()
poco("退出").click()
name = poco("com.kuke:id/tv_nick_name").get_text()
assert_equal(name, "登录/注册",msg="断言是否成功退出登录")



# generate html report
# from airtest.report.report import simple_report
# simple_report(__file__, logpath=True)